<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd HH:mm:ss" @on-change="getTime">
				</DatePicker>
				<Button class="m-r10" v-on:click="getTimeGcollect(1)">今日</Button>
				<Button class="m-r10" v-on:click="getTimeGcollect(2)">近7天</Button>
				<Button class="m-r10" v-on:click="getTimeGcollect(3)">近30天</Button>
				<Button type="primary" v-on:click="getCollectListQuery">查询</Button>
			</Form>
		</div>
		<fieldset>
			<legend>汇总</legend>
			<div>
				<tbody>
					<tr>
						<td>累积充值积分:
							<span class="blue">{{ list.rechargeSum == null ? 0 : list.rechargeSum }}</span>
						</td>
						<td>累积消费积分:
							<span class="blue">{{ list.incomeSum == null ? 0 : list.incomeSum }}</span>
						</td>
						<td>累积转赠积分:
							<span class="blue">{{ list.sendNum == null ? 0 : list.sendNum }}</span>
						</td>
						<td>累积提币USDT:
							<span class="blue">{{ list.usdtNum == null ? 0 : list.usdtNum }}</span>
						</td>
					</tr>
					<tr>
						<td>累积分享奖励:
							<span class="blue">{{ list.nodeSum == null ? 0 : list.nodeSum }}</span>
						</td>
						<td>累积间接分享奖励:
							<span class="blue">{{ list.netSum == null ? 0 : list.netSum }}</span>
						</td>
						<td>累积发放奖池:
							<span class="blue">{{ list.poolNum == null ? 0 : list.poolNum }}</span>
						</td>
						<td>累积销售产品:
							<span class="blue">{{ list.orderNum == null ? 0 : list.orderNum }}</span>
						</td>
					</tr>
				</tbody>
			</div>
		</fieldset>
		<fieldset>
			<legend>时间段汇总(<span v-text="day"></span>)</legend>
			<div>
				<table>
					<tbody>
					<tr>
						<td>累积充值积分:
							<span class="blue">{{ timeGcollect.rechargeSum == null ? 0 : timeGcollect.rechargeSum }}</span>
						</td>
						<td>累积消费积分:
							<span class="blue">{{ timeGcollect.incomeSum == null ? 0 : timeGcollect.incomeSum }}</span>
						</td>
						<td>累积转赠积分:
							<span class="blue">{{ timeGcollect.sendNum == null ? 0 : timeGcollect.sendNum }}</span>
						</td>
						<td>累积提币USDT:
							<span class="blue">{{ timeGcollect.usdtNum == null ? 0 : timeGcollect.usdtNum }}</span>
						</td>
					</tr>
					<tr>
						<td>累积分享奖励:
							<span class="blue">{{ timeGcollect.nodeSum == null ? 0 : timeGcollect.nodeSum }}</span>
						</td>
						<td>累积间接分享奖励:
							<span class="blue">{{ timeGcollect.netSum == null ? 0 : timeGcollect.netSum }}</span>
						</td>
						<td>累积发放奖池:
							<span class="blue">{{ timeGcollect.poolNum == null ? 0 : timeGcollect.poolNum }}</span>
						</td>
						<td>累积销售产品:
							<span class="blue">{{ timeGcollect.orderNum == null ? 0 : timeGcollect.orderNum }}</span>
						</td>
					</tr>
				</tbody>
				</table>
			</div>
		</fieldset>
		<Button class="daochu" type="primary" size="large" @click="exportData">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns" :data='collectList' ref="table"></Table>
		<!--<Page :total="info" :page-size="pageSize" show-elevator show-total @on-change="getCollectList"></Page>-->
	</div>
</template>
<script>
	export default {
		data() {
			return {
				day: '', // 时间显示(今日,近7天,近30天)
				list: [], // 财务汇总统计
				timeGcollect: [], // 时间段汇总
				collectList: [], // 财务统计列表的数据
				dataValue: [], // 时间段值
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				columns: [{
						title: '日期',
						key: 'createTime',
						align: 'center',
						sortable: true,
						fixed: 'left'
					},
					{
						title: '累积充值积分',
						align: 'center',
						key: 'rechargeSum'
					},
					{
						title: '累积消费积分',
						align: 'center',
						key: 'incomeSum'
					},
					{
						title: '累积转赠积分',
						align: 'center',
						key: 'sendNum'
					},
					{
						title: '累积提币USDT',
						align: 'center',
						key: 'usdtNum'
					},
					{
						title: '累积分享奖励',
						align: 'center',
						key: 'nodeSum'
					},
					{
						title: '累积间接分享奖励',
						align: 'center',
						key: 'netSum'
					},
					{
						title: '累积发放奖池',
						align: 'center',
						key: 'poolNum'
					},
					{
						title: '累积销售产品',
						align: 'center',
						key: 'orderNum'
					}
				]
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			});
			this.$nextTick(()=>{
				this.getGcollect(); // 财务汇总统计查询
				this.getTimeGcollect(1); // 财务汇总按照时间段查询(默认查找今天)
				this.getCollectList(); // 财务统计列表查询
			})
		},
		methods: {
			exportData() {
				this.$refs.table.exportCsv({
					filename: '财务统计'
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			getCollectList() { // 财务统计列表查询
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					startTime: '2000-12-30 00:00:00', // 起始日期
					endTime: '2200-12-30 00:00:00' // 结束日期
				})
				this.axios.post('financial/collectList', params, {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.collectList = res.data.data.financialListVOList;
						this.info = res.data.data.total;
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			cuctGetCollectList() { // 财务统计列表分页查询

			},
			getCollectListQuery() { // 财务统计列表条件查询
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0], // 起始日期
					endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1] // 结束日期
				})
				this.axios.post('financial/collectList', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008 || res.data.code == 4004) {
						this.collectList = res.data.data.financialListVOList;
						this.info = res.data.data.total;
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem('mytoken');
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			getGcollect() { // 	财务统计汇总
				let token = localStorage.getItem('mytoken');
				let params = this.qs.stringify({
					typeId: ''
				})
				this.axios.post('financial/pcollect',params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.list = res.data.data.financialListVO;
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem('mytoken');
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			getTimeGcollect(index) { // 时间段汇总
				if(index == 1) {
					this.day = '今日';
				}
				if(index == 2) {
					this.day = '近7天';
				}
				if(index == 3) {
					this.day = '近30天';
				}
				let token = localStorage.getItem('mytoken');
				let params = this.qs.stringify({
					typeId: index
				})
				this.axios.post('financial/pcollect',params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.timeGcollect = res.data.data.financialListVO;
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem('mytoken');
						this.$router.push({
							name: 'login'
						})
					}
				})
			}
		}
	}
</script>